package com.ss.web.tagmark.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.Random;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Transient;

import org.apache.commons.lang3.StringUtils;

@Entity
public class Annotation implements Serializable {
	private static final long serialVersionUID = -4807179027426343191L;
	@Transient
	private static final char[] color_chars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
			'E', 'F' };
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long annotationId;
	@Column
	private Long articleId;
	@Column
	private String segment;
	@Column
	private String partOfSpeech;
	@Column
	private Integer offset;
	@Column
	private String remark;
	@Column
	private Long operId;
	@Column
	private Date operTime;
	@Transient
	private String color;
	@Transient
	private String speechLabel;

	public Long getAnnotationId() {
		return annotationId;
	}

	public void setAnnotationId(Long annotationId) {
		this.annotationId = annotationId;
	}

	public Long getArticleId() {
		return articleId;
	}

	public void setArticleId(Long articleId) {
		this.articleId = articleId;
	}

	public String getSegment() {
		return segment;
	}

	public void setSegment(String segment) {
		this.segment = segment;
	}

	public String getPartOfSpeech() {
		return partOfSpeech;
	}

	public void setPartOfSpeech(String partOfSpeech) {
		this.partOfSpeech = partOfSpeech;
	}

	public Integer getOffset() {
		return offset;
	}

	public void setOffset(Integer offset) {
		this.offset = offset;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public Long getOperId() {
		return operId;
	}

	public void setOperId(Long operId) {
		this.operId = operId;
	}

	public Date getOperTime() {
		return operTime;
	}

	public void setOperTime(Date operTime) {
		this.operTime = operTime;
	}

	public String getColor() {
		if (StringUtils.isBlank(color)) {
			Random r = new Random(getOffset() * 1000000L + getSegment().length());
			StringBuilder sb = new StringBuilder("#");
			while (sb.length() < 6) {
				sb.append(color_chars[r.nextInt(color_chars.length)]);
			}
			color = sb.toString();
		}
		return color;
	}

	public void setColor(String color) {
		this.color = color;
	}

	public String getSpeechLabel() {
		return speechLabel;
	}

	public void setSpeechLabel(String speechLabel) {
		this.speechLabel = speechLabel;
	}
}
